package arithmetic1.search;

/*
    线性查找
 */
public class LinearSearch {
    public static void main(String[] args) {
        int arr[]={1,5,7,8,2,6,8};
        int index=linearSearch(arr,10);
        System.out.println(index);
    }

    //线性查找  arr为查找的范围 num为需要查找的数
    public static int linearSearch(int arr[],int num){
        for (int i = 0; i < arr.length; i++) {
            if(num==arr[i]){
                return i;
            }
        }
        return -1;
    }
}
